using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using UniversityManagerWebSite.Models;
using UniversityManagerWebSite.Models.Validation;
using Services;
using IServices;
using GestionLinqLibData;


namespace UniversityManagerWebSite.Controllers
{
    public class EleveController : Controller
    {
        private IEleveService _service;

        //
        // GET: /Home/
        public EleveController()
        {
            _service = new EleveService(new ModelStateWrapper(this.ModelState));
        }

        public EleveController(IEleveService service)
        { _service = service; }


        public ActionResult Index()
        {
            return View(_service.ListEleves());
        }

        //
        // GET: /Home/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Home/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Home/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude = "num_inscription")] eleve eleveToCreate)
        {
            if (_service.CreateEleve(eleveToCreate)) return RedirectToAction("index");
            return View();
        }

        //
        // GET: /Home/Edit/5

        public ActionResult Edit(int id)
        {

            return View(_service.GetEleve(id));
        }

        //
        // POST: /Home/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(eleve eleveEdited)
        {
            if (_service.EditEleve(eleveEdited)) return RedirectToAction("index");
            return View();

        }
        public ActionResult Delete(int id)
        {

            return View(_service.GetEleve(id));
        }

        //
        // POST: /Home/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Delete(eleve eleveToDelete)
        {
            if (_service.DeleteEleve(eleveToDelete)) return RedirectToAction("index");
            return View(eleveToDelete);

        }
   
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Cancel()
        {
            return RedirectToAction("index");
            

        }


    }

}
